         .TITLE  LP-11 PRINTER HANDLER
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;                                                                   ;
 ;                       SYSTEM TABLE CONTENTS                       ;
 ;                                                                   ;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
         .ASECT          ; INTERRUPT HANDLER LOCATION IN VECTORS
 .=200
         LP$INT
         200
 
         .CSECT  TABLES
         .BLKW   128.    ; OPERATOR XFER TABLE
         .REPT   6
         .BLKW   3
         .ENDR
         .WORD   OUTBIT,LPSTRT,LPABRT
         .PAGE
         .CSECT  LPDRVR
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;                                                                   ;
 ;               PRINTER OUTPUT HANDLER                              ;
 ;                                                                   ;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 LPUNIT: .WORD   0
 LPBUFA: .WORD
 LPLENG: .WORD
 LP.COL: .WORD   0
 LPCSR:  .WORD   177514
 LPBUF:  .WORD   177516

 LPOFST  = 4
 LPSTRT:         ; THIS CODE STARTS IO'S TO THE PRINTER DEVICE
         TST     LPUNIT          ; SEE IF AN IO ALREADY IN PROGRESS
         BNE     LPSTRT          ; IF SO LOOP UNTIL THE IO IS COMPLETE
         MTPS    #200            ; NO INTERRUPTS PLEASE
         MOV     R1,LPUNIT       ; MARK HANDLER AS BUSY
         BIS     #BSYBIT,(R1)    ; MARK LOGICAL UNIT AS BUSY
         CLR     (SP)            ; SET UP RETURN STUFF ON STACK...PR-0 PS
         TST     (R3)+           ; SKIP R3 OVER IO INFO WORD
         MOV     R3,-(SP)        ; NOW THE RETURN ADDRESS
         MOV     <UBUFFR+LPOFST>(SP),LPBUFA      ; GRAB USER BUFFER ADDR
         MOV     <URLENG+LPOFST>(SP),LPLENG      ; AND REQUESTED IO LENGTH
 LP$INT: BIC     #100,@LPCSR     ; DISABLE INTERRUPTS
         TST     LPUNIT          ; ANY IO'S IN PROGRESS
         BEQ     LPEXIT          ; IF NOT JUST FORGET IT
         TST     LPLENG          ; ANY CHARS LEFT TO BE SENT?
         BEQ     LPQUIT          ; IF NOT THEN FINISH UP IO
         MOV     R0,-(SP)        ; STASH REG
         CLR     R0
         BISB    @LPBUFA,R0      ; GRAB CHAR FROM USER BUFFER
         BEQ     3$              ; A NULL? RESET TABS STOPS
         CMPB    R0,#FF          ; FORM - FEED?
         BEQ     3$
         CMPB    R0,#HT
         BNE     4$
         JSR     PC,LPTABR
 4$:     INC     LP.COL
         CMPB    R0,#CR          ; AN END-OF-LINE CHAR?
         BNE     1$
         MOVB    #LF,R0          ; MAKE A PRINTRONIX EOL
         BR      3$
 1$:     CMPB    R0,#21          ; A DC1?? (USED TO DO UNDERLINING)
         BNE     2$
         MOVB    #CR,R0          ; MAKE A CR FOR PRINTRONIX BENEFIT
 3$:     CLR     LP.COL
 2$:     TST     @LPCSR          ; TEST ERROR BIT
         BMI     2$              ; AND HANG TIL READY
         MOVB    R0,@LPBUF       ; SEND CHAR TO DL
         MOV     (SP)+,R0        ; RESTORE TEMP REG
         BIS     #100,@LPCSR     ; ALLOW INTERRUPT
         INC     LPBUFA          ; BUMP BUFFER POINTER TO NEXT CHAR
         DEC     LPLENG          ; ALSO REFLECT ONE FEWER CHAR TO SEND
         JMP     @#INTRTN        ; THIS STRUCTURE IMPLIES AN IO IS NOT
                                 ; DONE UNTIL THE LAST INTERRUPT IS RECEIVED
 LPQUIT: BIC     #BSYBIT,@LPUNIT         ; CLEAR BUSY BIT IN IO UNIT TABLE
         CLR     LPUNIT          ; MARK HANDLER AS NOT BUSY NOW
 LPEXIT: JMP     INTRTN          ; AND BACK NOW TO WHEREVER

 LPTABR: ; LITTLE SUBROUTINE TO TAB
         MOV     R1,-(SP)
         MOV     #' ,R0
         MOV     LP.COL,R1
         BIS     #7,LP.COL
         SUB     LP.COL,R1
         BEQ     3$
 1$:     MOVB    R0,@LPBUF
 2$:     TSTB    @LPCSR
         BPL     2$
         INC     R1
         BNE     1$
 3$:     MOV     (SP)+,R1
         RTS     PC

 LPABRT: MTPS    #200
         TST     LPUNIT
         BEQ     1$
         BIC     #BSYBIT,@LPUNIT
         CLR     LPUNIT
 1$:     MTPS    #0
         RTS     PC

         .END


